package com.yywq.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author: 吴磊
 * @program: yywq
 * @create: 2021-03-18 18:46
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
@Repository
/**
 * 返回前端的统一的返回结果
 */
public class CommonReturnType {
    //表明对应请求的返回处理结果  "success" 或  "false"
    private String status;
    //若 status  = success，则data返回前端需要的json数据
    //若 status  = fail，则data使用通用的错误码格式
    private Object data;

    //定义一个通用的创建方法
    public static CommonReturnType create(Object data) {
        return CommonReturnType.create(data, "success");
    }


    public static CommonReturnType create(Object data, String status) {
        CommonReturnType commonReturnType = new CommonReturnType();
        commonReturnType.setStatus(status);
        commonReturnType.setData(data);
        return commonReturnType;
    }
}
